Fixed expressions in gtk_button_size_allocate()
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Sat, 7 Aug 2010 21:41:29 +0000 (17:41 -0400)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Sat, 7 Aug 2010 21:41:29 +0000 (17:41 -0400)
Children were getting negative allocations by misusage
of MAX() macro (bad signedness of expressions).

gtk/gtkbutton.c

index 9b2f47557112eefc1e5d8ca5e04d0c757ef3658d..e9527c189a3ff5ea005e244522d56214d64a797e 100644 (file)
@@ -1476,31 +1476,34 @@ gtk_button_size_allocate (GtkWidget     *widget,
       child_allocation.x = widget->allocation.x + border_width + inner_border.left + xthickness;
       child_allocation.y = widget->allocation.y + border_width + inner_border.top + ythickness;
       
-      child_allocation.width = MAX (1, widget->allocation.width -
-                                    xthickness * 2 -
-                                    inner_border.left -
-                                    inner_border.right -
-                                   border_width * 2);
-      child_allocation.height = MAX (1, widget->allocation.height -
-                                     ythickness * 2 -
-                                     inner_border.top -
-                                     inner_border.bottom -
-                                    border_width * 2);
+      child_allocation.width = 
+       widget->allocation.width -
+       xthickness * 2 -
+       inner_border.left -
+       inner_border.right -
+       border_width * 2;
+
+      child_allocation.height = 
+       widget->allocation.height -
+       ythickness * 2 -
+       inner_border.top -
+       inner_border.bottom -
+       border_width * 2;
 
       if (gtk_widget_get_can_default (GTK_WIDGET (button)))
        {
          child_allocation.x += default_border.left;
          child_allocation.y += default_border.top;
-         child_allocation.width =  MAX (1, child_allocation.width - default_border.left - default_border.right);
-         child_allocation.height = MAX (1, child_allocation.height - default_border.top - default_border.bottom);
+         child_allocation.width =  child_allocation.width - default_border.left - default_border.right;
+         child_allocation.height = child_allocation.height - default_border.top - default_border.bottom;
        }
 
       if (gtk_widget_get_can_focus (GTK_WIDGET (button)))
        {
          child_allocation.x += focus_width + focus_pad;
          child_allocation.y += focus_width + focus_pad;
-         child_allocation.width =  MAX (1, child_allocation.width - (focus_width + focus_pad) * 2);
-         child_allocation.height = MAX (1, child_allocation.height - (focus_width + focus_pad) * 2);
+         child_allocation.width =  child_allocation.width - (focus_width + focus_pad) * 2;
+         child_allocation.height = child_allocation.height - (focus_width + focus_pad) * 2;
        }
 
       if (button->depressed)
@@ -1516,6 +1519,9 @@ gtk_button_size_allocate (GtkWidget     *widget,
          child_allocation.y += child_displacement_y;
        }
 
+      child_allocation.width  = MAX (1, child_allocation.width);
+      child_allocation.height = MAX (1, child_allocation.height);
+
       gtk_widget_size_allocate (child, &child_allocation);
     }
 }